package action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import model.Doctor;
import model.QandA;
import model.User;
import org.apache.struts2.interceptor.ParameterAware;
import service.AskDoctorService;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: TM
 * Date: 11/17/12
 * Time: 12:19 PM
 * To change this template use FileModel | Settings | FileModel Templates.
 */
public class AskDoctorAction  implements ModelDriven, ParameterAware {
    private AskDoctorService askDoctorService;
    private List<Doctor> doctorList;
    private User user;
    private Map<String, String[]> parameters;
    private List<QandA> doctorResponse;

    public Object getModel() {
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        user = (User) session.get("USER");
        return user;
    }


    public String retrieveDoctorList() throws Exception {
         ActionContext ctx = ActionContext.getContext();
         Map session = ctx.getSession();
         doctorList = askDoctorService.getDoctorList((User) session.get("USER"));
         return "askDoctor";
    }

    public String saveQuestion(){
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        QandA qanda = new QandA();
        qanda.setDoctorId(parameters.get("doctor")[0]);
        qanda.setQuestion(parameters.get("question")[0]);
        askDoctorService.saveQuestion((User) session.get("USER"), qanda);
        doctorList = askDoctorService.getDoctorList((User) session.get("USER"));
        return "askDoctor";
    }

    public String   viewDoctorResponse(){
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        doctorResponse = askDoctorService.getQandA((User)session.get("USER"));
        System.out.println("------"+doctorResponse.size());
        return "askDoctorResponse";
    }

    public AskDoctorService getAskDoctorService() {
        return askDoctorService;
    }

    public void setAskDoctorService(AskDoctorService askDoctorService) {
        this.askDoctorService = askDoctorService;
    }

    public List<Doctor> getDoctorList() {
        return doctorList;
    }

    public void setDoctorList(List<Doctor> doctorList) {
        this.doctorList = doctorList;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Map<String, String[]> getParameters() {
        return parameters;
    }

    public void setParameters(Map<String, String[]> parameters) {
        this.parameters = parameters;
    }

    public List<QandA> getDoctorResponse() {
        return doctorResponse;
    }

    public void setDoctorResponse(List<QandA> doctorResponse) {
        this.doctorResponse = doctorResponse;
    }
}
